package org.groupg.project.a;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

//2. 值对象类 - FullName.java
public class FullName {
    @JacksonXmlProperty(localName = "FirstName")
    private String firstName;

    @JacksonXmlProperty(localName = "LastName")
    private String lastName;

    public FullName() {} // 默认构造器

    @JsonCreator
    public FullName(
            @JsonProperty("first") String firstName,
            @JsonProperty("last") String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    // 添加 toString() 方法用于自定义序列化
    @Override
    public String toString() {
        return firstName + " " + lastName;
    }

    // Getter 和 Setter
    public String getFirstName() { return firstName; }
    public void setFirstName(String firstName) { this.firstName = firstName; }
    public String getLastName() { return lastName; }
    public void setLastName(String lastName) { this.lastName = lastName; }

    // 添加静态工厂方法用于反序列化
    public static FullName fromString(String fullName) {
        if (fullName == null || fullName.isEmpty()) return null;
        String[] parts = fullName.split(" ");
        return new FullName(
            parts.length > 0 ? parts[0] : "",
            parts.length > 1 ? parts[1] : ""
        );
    }
}